package com.example.service.configuration.impl;

import com.example.bean.configuration.LieBiao;
import com.example.bean.configuration.PingGuMoBan;
import com.example.bean.configuration.ZhiBiaoGuanLi;
import com.example.bean.configuration.vo.ZhiBiaoGuanLiVo;
import com.example.mapper.configuration.ZhiBiaoGuanLiMapper;
import com.example.service.configuration.ZhiBiaoGuanLiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ZhiBiaoGuanLiServiceImpl implements ZhiBiaoGuanLiService {

    @Autowired
    ZhiBiaoGuanLiMapper mapper;


    @Override
    public PageInfo<ZhiBiaoGuanLi> getpage(ZhiBiaoGuanLiVo vo) {
        PageHelper.startPage(vo.getDqNum(),vo.getXsNum());
        PageInfo<ZhiBiaoGuanLi> page = new PageInfo<ZhiBiaoGuanLi>(mapper.getpage(vo));
        return page;
    }

    @Override
    public Integer addzbgl(ZhiBiaoGuanLi zhiBiaoGuanLi) {
        Integer a = mapper.addzbgl(zhiBiaoGuanLi);
        if(a > 0){
            for (LieBiao lieBiao : zhiBiaoGuanLi.getFormarr()){
                mapper.addxiangzhi(zhiBiaoGuanLi.getNoid(),lieBiao.getZhibiao(),lieBiao.getStatus());
                System.err.println("添加时的数据："+lieBiao);
            }
        }
        return a;
    }

    @Override
    public ZhiBiaoGuanLi getId(String aid) {
        ZhiBiaoGuanLi zhiBiaoGuanLi = mapper.getId(aid);
        ArrayList<LieBiao> lieBiao = mapper.getliebiao(aid);
        zhiBiaoGuanLi.setFormarr(lieBiao);
        return zhiBiaoGuanLi;
    }

    @Override
    public Integer editzbgl(ZhiBiaoGuanLi zhiBiaoGuanLi) {
        Integer a = mapper.delliebiao(zhiBiaoGuanLi.getNoid());
        if(a > 0){
            for (LieBiao lieBiao : zhiBiaoGuanLi.getFormarr()){
                mapper.addxiangzhi(zhiBiaoGuanLi.getNoid(),lieBiao.getZhibiao(),lieBiao.getStatus());
            }
        }
        Integer b = mapper.editzbgl(zhiBiaoGuanLi);
        return b;
    }

    @Override
    public Integer dels(List<String> ids) {
        return mapper.dels(ids);
    }
}
